﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CBMS.Uc;
using CBMS.View;
using CBMS.Business;
using CBMS.Interfaces;
using CBMS.Models;
namespace CBMS
{
    public partial class frmMain : frmBase
    {
        #region Fields
        
        #endregion

        #region Init,load
        public frmMain()
        {
            InitializeComponent();
        }
        #endregion

        #region Method
        private void AddControl(BaseControl ctr)
        {
            panelMain.Controls.Clear();
            ctr.Dock = System.Windows.Forms.DockStyle.Fill;
            ctr.Location = new System.Drawing.Point(0, 0);
            Common.CommonFunction.SetLoginData(ctr, this);
            panelMain.Controls.Add(ctr);
        }
        private void CheckPermission()
        {
            //string role = "admin";
            //string disableTab = "ribTabHome|RibbonTab";
            //string[] arrTab = disableTab.Split('|');
            //List<System.Windows.Forms.RibbonTab> lstTab = new List<RibbonTab>();
            //foreach (System.Windows.Forms.RibbonTab ctr in ribMainMenu.Tabs)
            //{
            //    if (ctr.Text == "Payment")
            //        lstTab.Add(ctr);
            //    //foreach (string tab in arrTab)
            //    //{

            //    //}
            //}
            //foreach (System.Windows.Forms.RibbonTab ctr in lstTab)
            //{
            //    ribMainMenu.Tabs.Remove(ctr);
            //}
        }
        private void AddFrom(frmBase f)
        {
            Common.CommonFunction.ShowForm(f, this);
        }

        void login_LoginSystem(object sender, EventArgs e)
        {
            frmLogin login = (frmLogin)sender;
            if (login.userLogin != string.Empty)
            {
                IStaffRepository staffRes = new StaffRepository();
                Staff objStaff = staffRes.GetByUserName(login.userLogin);
                this.userLogin = objStaff.user_name;
                this.userLoginRole = objStaff.role_code;
                this.userLoginBranch = objStaff.branch_id;
                this.userLoginId = objStaff.staff_id;
                this.Show();
                login.Close();
            }
        }
        #endregion

        #region Events
        private void ribButtonMakeBooking_Click(object sender, EventArgs e)
        {
            BaseControl ucBase = new ucMakeBookingStep1();
            AddControl(ucBase);
        }
        private void ribButtonTodayBooking_Click(object sender, EventArgs e)
        {

        }
        private void ribButtonShowCalendar_Click(object sender, EventArgs e)
        {
            BaseControl ucBase = new ucMainCalendar();
            AddControl(ucBase);
        }
        private void ribButtonNewBooking_Click(object sender, EventArgs e)
        {

        }
        private void ribButtonCurrentBooking_Click(object sender, EventArgs e)
        {

        }
        private void ribButtonPaynow_Click(object sender, EventArgs e)
        {

        }
        private void ribButtonStaffTable_Click(object sender, EventArgs e)
        {

        }
        private void ribButtonWaitPayment_Click(object sender, EventArgs e)
        {

        }
        private void ribButtonPaidBooking_Click(object sender, EventArgs e)
        {

        }
        private void ribButtonNewMember_Click(object sender, EventArgs e)
        {
            frmBase frm = new frmMemberDetail();
            AddFrom(frm); 
        }
        private void ribButtonStaffSearch_Click(object sender, EventArgs e)
        {
            BaseControl ucBase = new CBMS.Uc.usStaffList();
            AddControl(ucBase);
        }
        private void ribButtonCurentWorkingList_Click(object sender, EventArgs e)
        {

        }
        private void ribButtonNewStaff_Click(object sender, EventArgs e)
        {
            frmBase f = new frmStaffDetail();
            AddFrom(f);
        }
        private void ribTabMember_ActiveChanged(object sender, EventArgs e)
        {
            ribButtonSearchMembers_Click(null, null);
        }
        private void ribTabStaff_ActiveChanged(object sender, EventArgs e)
        {
            ribButtonStaffSearch_Click(null, null);
        }
        private void ribTabHome_ActiveChanged(object sender, EventArgs e)
        {
            if (this.ribTabHome.Active)
            {
                BaseControl ucBase = new ucFlash();
                AddControl(ucBase);
            }
        }
        private void ribButtonSearchMembers_Click(object sender, EventArgs e)
        {
            BaseControl ucBase = new CBMS.Uc.ucMemberList();
            AddControl(ucBase);
        }
        private void ribPanelLogout_Click(object sender, EventArgs e)
        {

        }
        private void ribtnLogout_Click(object sender, EventArgs e)
        {

        }
        private void frmMain_Load(object sender, EventArgs e)
        {

        }
        private void ribbtnLogout_Click(object sender, EventArgs e)
        {
            frmLogin login = new frmLogin(false);
            login.userLogin = string.Empty;            
            login.FormClosing += delegate { if(this.userLogin==string.Empty) this.Close();  };
            login.LoginSystem += new EventHandler(login_LoginSystem);
            login.Show();
            this.Hide();
        }
        private void ribbtnEditProfile_Click(object sender, EventArgs e)
        {
            frmBase f = new frmStaffDetail(true);          
            AddFrom(f);
        }
        private void ribbtnChangePass_Click(object sender, EventArgs e)
        {
            frmBase f = new frmChangePassword(this.userLoginId);
            AddFrom(f);
        }
        #endregion

        private void ribbonPanelSystemConfig_Click(object sender, EventArgs e)
        {
            frmBase frm = new frmSystemConfig();
            AddFrom(frm); 
        }       
    }
}